/**
 * Copyright (C), 2001-2023, www.bosssof.com.cn
 * FileName: UserApi
 * Author: Administrator
 * Date: 2023-03-30 16:00:07
 * Description:
 * <p>
 * History:
 * <author> Administrator
 * <time> 2023-03-30 16:00:07
 * <version> 1.0.0
 * <desc> 版本描述
 */
package com.bosssoft.usercenter.api;

import com.bosssoft.usercenter.pojo.dto.IdVersion;
import com.bosssoft.usercenter.pojo.dto.ResourceDTO;
import com.bosssoft.usercenter.pojo.query.ResourceQuery;
import com.bosssoft.usercenter.pojo.vo.CommonPage;
import com.bosssoft.usercenter.pojo.vo.CommonResponse;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: ResourceApi
 * @Description: 有用配合前端演示资源增删改查的demo
 * @Author: Administrator
 * @Date: 2023-03-30 16:00
 **/

@CrossOrigin
@Api(tags = "资源管理 ", value = "/api/v1/permission/resource")
@RequestMapping("/api/v1/permission/resource")
@Validated
public interface ResourceApi {
    /**
     * 界面调用接口增加资源
     *
     * @param resourceDTO 资源信息
     * @return true成功 false失败
     */
    @ApiOperation(value = "增加资源", notes = "界面增加资源")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "请求执行没有成功但是发生异常")})
    @PostMapping("/resource")
    CommonResponse<Boolean> add(@NotNull @Valid @RequestBody @ApiParam(value = "资源数据", required = true) ResourceDTO resourceDTO);

    /**
     * 删除资源
     *
     * @param id 记录id
     * @return true 成功 false失败
     */
    @ApiOperation(value = "删除资源通过id", notes = "通过id删除资源")
    @ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "path")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @DeleteMapping("/resource")
    CommonResponse<Boolean> remove(@PathVariable @NotNull Long id);

    /**
     * 通过id和version比较删除资源
     *
     * @param id      记录id
     * @param version 版本
     * @return true 成功 false失败
     */
    @ApiOperation(value = "删除资源通过id和版本", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "version", required = true, dataType = "Long", paramType = "query")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @DeleteMapping("/optimism/resource")
    CommonResponse<Boolean> remove(@NotNull @RequestParam("id") Long id, @NotNull @RequestParam("version") Long version);

    /**
     * 批量删除资源
     *
     * @param idVersions
     * @return
     */
    @ApiOperation(value = "批量删除资源通过id和版本", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions", required = true, dataType = "IdVersion", paramType = "body")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @DeleteMapping("/batch/resource")
    CommonResponse<Boolean> remove(@NotEmpty @RequestBody IdVersion[] idVersions);


    /**
     * 界面调用接口更新资源信息
     *
     * @param resourceDTO 资源信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "更新资源信息", notes = "修改界面保存调用该方法")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @PutMapping("/resource")
    CommonResponse<Boolean> update(@NotNull @Valid @RequestBody @ApiParam ResourceDTO resourceDTO);

    /**
     * 界面调用接口更新资源信息
     *
     * @param resourceQuery 资源信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "查询资源列表接口", notes = "支持模糊查询")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @GetMapping("/resource")
    CommonResponse<CommonPage<ResourceDTO>> search(@NotNull @Valid @RequestBody ResourceQuery resourceQuery);

    /**
     * 页面编辑行的时候传id从后端加载数据
     *
     * @param id 当前行id
     * @return 资源数据
     */
    @ApiOperation(value = "根据id获取资源接口", notes = "用于编辑和查看的时候获取资源")
    @ApiImplicitParam(name = "id", value = "主键值", required = true, dataType = "Long", paramType = "path")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功,非0码则代表失败"),})
    @GetMapping("/resource/{id}")
    CommonResponse<ResourceDTO> findById(@PathVariable @NotNull Long id);
}
